#include "../../include/DirScanner.h"

#include <dirent.h>
#include <sys/types.h>
    
DirScanner::DirScanner(const string &path)
: _path(path)
{

}

DirScanner::~DirScanner()
{

}

//返回指定目录下所有文件的路径集合
vector<string> DirScanner::getFilesPath()
{
    string basepath = _path;
    DIR * dir = opendir(_path.c_str());
    if(0 == dir) {
        perror("opendir");
        exit(-1);
    }

    struct dirent* pdirent;
    string tmp;
    while((pdirent = readdir(dir)) != nullptr) {
        tmp = basepath;
        if(pdirent->d_name[0] != '.') {
            tmp.append("/").append(pdirent->d_name);
            _filesPath.push_back(tmp);
        }
    }
    free(dir);
    return _filesPath;
}